package com.ruoyi.system.service.impl;

import java.util.Collections;
import java.util.Comparator;
import java.util.List;

import com.ruoyi.system.domain.DayElecInfo;
import com.ruoyi.system.domain.vo.DayElecInfoVo;
import com.ruoyi.system.domain.vo.ElecCityCountVo;
import com.ruoyi.system.mapper.DayElecInfoMapper;
import com.ruoyi.system.domain.dto.ElecInfoDto;
import com.ruoyi.system.domain.vo.WeekElecInfoVo;
import org.springframework.stereotype.Service;
import com.ruoyi.system.service.IDayElecInfoService;

import javax.annotation.Resource;

/**
 * 每日用电情况Service业务层处理
 * 
 * @author handsome
 * @date 2024-07-03
 */
@Service
public class DayElecInfoServiceImpl implements IDayElecInfoService 
{
    @Resource
    private DayElecInfoMapper dayElecInfoMapper;

    @Override
    public List<ElecCityCountVo> selectCityElecSumYesterday() {
        return dayElecInfoMapper.selectCityElecSumYesterday();
    }

    /**
     * 查询每日用电情况
     * 
     * @param userId 每日用电情况主键
     * @return 每日用电情况
     */
    @Override
    public DayElecInfo selectDayElecInfoByUserId(Long userId)
    {
        return dayElecInfoMapper.selectDayElecInfoByUserId(userId);
    }

    @Override
    public List<DayElecInfoVo> selectLastWeekElecByUserId(Long userId) {
        return dayElecInfoMapper.selectLastWeekElecByUserId(userId);
    }

    /**
     * 用户每周的用电情况
     * @param userId
     * @return
     */
    @Override
    public List<WeekElecInfoVo> selectLastMonthElecByUserId(Long userId) {
        List<WeekElecInfoVo> weekElecInfoVos = dayElecInfoMapper.selectLastMonthElecByUserId(userId);
        Collections.sort(weekElecInfoVos, new Comparator<WeekElecInfoVo>() {
            @Override
            public int compare(WeekElecInfoVo o1, WeekElecInfoVo o2) {
                return Integer.compare(o1.getWeek(),o2.getWeek());
            }
        });
        return weekElecInfoVos;
    }

    /**
     * 查询每日用电情况列表
     * 
     * @param dayElecInfo 每日用电情况
     * @return 每日用电情况
     */
    @Override
    public List<DayElecInfo> selectDayElecInfoList(DayElecInfo dayElecInfo)
    {
        return dayElecInfoMapper.selectDayElecInfoList(dayElecInfo);
    }

    /**
     * 新增每日用电情况
     * 
     * @param dayElecInfo 每日用电情况
     * @return 结果
     */
    @Override
    public int insertDayElecInfo(ElecInfoDto dayElecInfo)
    {
        return dayElecInfoMapper.insertDayElecInfo(dayElecInfo);
    }

    /**
     * 修改每日用电情况
     * 
     * @param dayElecInfo 每日用电情况
     * @return 结果
     */
    @Override
    public int updateDayElecInfo(DayElecInfo dayElecInfo)
    {
        return dayElecInfoMapper.updateDayElecInfo(dayElecInfo);
    }

    /**
     * 批量删除每日用电情况
     * 
     * @param userIds 需要删除的每日用电情况主键
     * @return 结果
     */
    @Override
    public int deleteDayElecInfoByUserIds(Long[] userIds)
    {
        return dayElecInfoMapper.deleteDayElecInfoByUserIds(userIds);
    }

    /**
     * 删除每日用电情况信息
     * 
     * @param userId 每日用电情况主键
     * @return 结果
     */
    @Override
    public int deleteDayElecInfoByUserId(Long userId)
    {
        return dayElecInfoMapper.deleteDayElecInfoByUserId(userId);
    }
}
